﻿using System;
using System.Collections.Generic;

namespace JT808Protocol.Models.BodyParserStrategy
{
    public class PrDeviceParamSet_0x8103 : IJT808Body
    {
        public byte ParamCount
        { get { return Convert.ToByte(ParamList.Count); } }

        public List<IDeviceParam> ParamList { get; private set; }

        public PrDeviceParamSet_0x8103()
        {
            ParamList = new List<IDeviceParam>();
        }

        /// <summary>
        /// 添加参数
        /// </summary>
        /// <param name="param"></param>
        public void AddParam(IDeviceParam param)
        {
            if (ParamList.IndexOf(param) == -1)
            {
                ParamList.Add(param);
            }
        }

        public override IJT808Body ReadBody(ReadOnlySpan<byte> data, ref int index)
        {
            throw new NotImplementedException();
        }

        public override List<byte> WriteToBytes()
        {
            if (ParamList.Count < 1)
            {
                throw new NullReferenceException("没有找到要设置的参数项");
            }
            List<byte> result = new List<byte>();

            //参数总数
            result.Add(Convert.ToByte(ParamList.Count));
            foreach (var param in ParamList)
            {
                result.AddRange(param.WriteToNetBytes());
            }

            return result;
        }
    }
}